package net.zjitc.service.impl;

import net.zjitc.dao.UserDao;
import net.zjitc.dao.impl.UserDaoImpl;
import net.zjitc.pojo.User;
import net.zjitc.service.UserService;
import net.zjitc.utils.CommonUtils;
import net.zjitc.utils.ControllerUtils;
import net.zjitc.utils.MailUtils;

import java.util.List;

/**
 * Created by Administrator on 2017/11/9.
 */
public class UserServiceImpl implements UserService {
    UserDao dao = new UserDaoImpl();
    public List<User> findAll() {
        return dao.findAll();
    }

    public User findByUsername(String username) {
        return dao.findByUsername(username);
    }

    public int save(User user) {
        //没有状态码 ，设置状态  1表示激活  0表示末激活
        user.setState(0);
        String code = CommonUtils.getUUID()+CommonUtils.getUUID();
        user.setCode(code);
        //发送一个邮件
        try {
            MailUtils.sendMail(user.getEmail(),code);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return  dao.save(user);

    }

    public User findByCode(String code) {
        return dao.findByCode(code);
    }

    public int update(User user) {
        return dao.update(user);
    }
}
